/**
 *
 */
package com.lingyun.ucm.web.mvc.controller;

import com.lingyun.ucm.common.pojo.bean.ClientReport;
import com.lingyun.ucm.web.mvc.service.ClientsService;
import com.lingyun.ucm.web.mvc.service.impl.ClientsServiceImpl;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Date;
import java.util.List;

/**
 * 
 * @author Terrence2013
 * 2018年1月24日 上午9:50:26
 * 接入客户端列表Servlet
 */
public class ClientsServlet extends HttpServlet {
    /**
     *
     */
    private static final long serialVersionUID = -2839345514565681004L;

    private ClientsService clientsService = new ClientsServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) {
        try {
            req.setCharacterEncoding("UTF-8");
            resp.setContentType("text/html;charset=utf-8");
            String operation = req.getParameter("operation");
            if(operation!=null){
                switch (operation){
                    case "refresh":
                        String systemIp = req.getParameter("systemIp");
                        clientsService.refreshClientConfig(systemIp);
                        break;
                    default:
                }
            }
            List<ClientReport> clientReportList = clientsService.listAll();
            req.setAttribute("clientReportList", clientReportList);
            req.setAttribute("currentTime", new Date());
            req.getRequestDispatcher("/WEB-INF/pages/clients.jsp").forward(req, resp);
        } catch (Exception e) {
            //异常不处理
        }
    }

}
